﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>盘点任务列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
    <script src="~/Scripts/formSelect/multiSelect.js"></script>

    <script type="text/html" id="barDemo">
        <a title="盘点清单" href="javascript:;" lay-event="dList" id="frmView"><i class="layui-icon">&#xe615;</i></a>
        <a title="已盘清单" href="javascript:;" lay-event="sp"  id="frmView"><i class="layui-icon">&#xe601;</i></a>
        {{# if(d.status !='pct-stop' && d.status !='pct-report'){}}
        <a title="终止" href="javascript:;" lay-event="stop" id="frmEdit"><i class="layui-icon">&#xe651;</i></a>
        {{# }}}
        {{# if(d.status !='pct-report'){}}
        <a title="删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>
        {{# }}}

    </script>

</head>
<body>
    <div class="layui-fluid">
        <div id="bDiv">
        </div>
        <div class="layui-card">
            <div class="layui-card-body" style="margin-top:5px">
                <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="venCode" placeholder="盘点单号" autocomplete="off" class="layui-input" id="venCode">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="erpCode" placeholder="关联单号" autocomplete="off" class="layui-input" id="erpCode">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="wareName" placeholder="仓库名称" autocomplete="off" class="layui-input" id="wareName">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="erpProCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="erpProCode">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="hidden" name="cStatus" id="cStatus">
                        <select multiple="multiple" lay-filter="multiple" id="status" name="status">
                            <option value="">盘点状态</option>
                        </select>
                    </div>
                </form>
            </div>
            <div>
                <span style="margin-left: 20px; padding: 7px; background-color: #C3FDB8; font-size: Xx-small">已生成报告</span>
            </div>

            <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                <table class="layui-hide" id="list" lay-filter="list"></table>
            </div>

        </div>

    </div>
</body>

</html>

<script>
    var webCode = "";
    var currPage = 1;//首先默认值为1，防止出错
    var pchCodes = "";

    var canCreatebg = true;

    $(function () {
        webCode = getUrlVariable("menuCode");
        BannerData(webCode, "bDiv");
        DictionaryDropDown("pcst", "status", "");
        loadData();
    })

    layui.use(['multiSelect'], function () {
        var $ = layui.jquery, form = layui.form, multiSelect = layui.multiSelect;
    });
    function GetSelectMore() {
        var vals = [],
            texts = [];
        $('select[multiple] option:selected').each(function () {
            vals.push($(this).val());
            texts.push($(this).text());
        })
        $("input[ name='cStatus']").val(vals.join(','));

    }

     var qStr="";
    /**
     * 获取高级查询字符串
     * **/
    function GetQueryPar(queryStr) {
      qStr=queryStr;
      loadData();
    }

    var dUrl = "../ProCheck/GetDataList?dataType=task&condition=";
    function loadData() {
        GetSelectMore();

        if (!gjQuery) {
            qStr = FormToJson("qForm");
        }
        gjQuery = false;
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { type: 'checkbox', fixed: 'left' }
              , { field: 'id', title: 'ID', width: 80 }
                , { field: 'venCode', align: 'center',title: '盘点单号', width: 110 }
                    , { field: 'erpCode', align: 'center', title: '关联单号', width: 110 }
                    , { field: 'wareName', align: 'center', title: '仓库名称', width: 110 }
                // , { field: 'positionName', align: 'center', title: '货位', width: '8%' }
                // , { field: 'erpProCode', align: 'center', title: '存货编码', width: '10%' }
                // , { field: 'proName', align: 'center', title: '存货名称', width: '13%' }
                    , { field: 'erpNumber', align: 'center', title: '用友账面数', width: 110 }
                    , { field: 'chTypeName', align: 'center', title: '盘点类型', width: 110 }
                    , { field: 'createtime', align: 'center', title: '创建时间', width: 130 }
                    , { field: 'statusName', align: 'center', title: '任务状态', width: 110 }
                    , { field: 'right', align: 'center', title: '数据操作', toolbar: '#barDemo', width: 100, fixed: 'right' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                currPage = curr;
                TablePowerHide();
                $.each(res['data'], function (i, j) {
                    if (j['status'] == "pct-report") {
                        TableRowColor('layui-table-main', i, '#C3FDB8');//已生成报告
                    }
                });
            }
            , url: dUrl + conditon
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [15, 30, 50]
            , limit: 15 //每页默认显示的数量
            , id: "list"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'del') {
                    layer.confirm('确认要删除选中任务？', { icon:3 }, function (index) {
                        var info = DelData(data.pchCode);

                        if (info.Result) {
                            obj.del();
                        } else {
                            layer.msg(info.message, { icon: 2 });
                        }
                        layer.close(index);
                        loadData();
                    });
                } else if (obj.event == 'dList') {
                    var title = "盘点单号：" + data.erpCode + "（" + data.chTypeName + "）明细";
                    InfoOpenPage('../ProCheck/CheckTaskList?dataType=chyp&pchCode=' + data.pchCode, title, "80%", "90%");
                }
                else if (obj.event == 'stop') {
                    layer.confirm('确认要中止此任务？', { icon: 3},function (index) {
                        $.ajax({
                            url: "../ProCheck/StopCheckTask",
                            data: { pchCode: data.pchCode },
                            dataType: "json",
                            type: "POST",
                            async: false,
                            success: function (data) {
                                loadData();
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event == 'sp') {
                   InfoOpenPage('../ProCheck/TaskRecords?pchCode=' + data.pchCode, data.erpCode + "（" + data.chTypeName + "）-实盘清单", "80%", "90%");
                }

            });
            //监听工具条
            table.on('checkbox(list)', function (obj) {
                var data = obj.data;
                var checkStatus = table.checkStatus('list');
                pchCodes = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    if (checkStatus.data[i].status != "pct-doing") {
                        layer.msg("此任务不能生成报告：" + checkStatus.data[i].erpCode, { icon: 2 }); return;
                    }
                    pchCodes += checkStatus.data[i].pchCode + ",";
                }
                pchCodes = pchCodes.substr(0, pchCodes.length - 1);

            });
        });
    }

    
    function addWin() {
        // InfoOpenPage("../ProCheck/UpdateTask?dataId=0", "创建盘点任务", "80%", "90%");
        var conditon = JSON.stringify(FormToJson("qForm"));
        NewOpenPage("../ProCheck/UpdateTask?dataId=0", "创建盘点任务", "85%", "80%", "list", currPage, dUrl + conditon);
    }

    /**
删除任务
**/
    function DelData(pchCode) {
        var info = undefined;
        $.ajax({
            url: "../ProCheck/DelCheckTask",
            data: { pchCode: pchCode },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                info= data;
            }
        });
        return info;
    }
    /**
    生成盘点报告
    **/
    function cReport() {
        if (!canCreatebg) {
            return;
        }

        canCreatebg = false;
        
        if (pchCodes != "") {
                var loadwin = layer.load(2, {
                    shade: [0.3, '#424242'],
                    content: '生成中',
                    success: function (layerContentStyle) {
                        layerContentStyle.find('.layui-layer-content').css({
                            'padding-top': '35px',
                            'text-align': 'left',
                            'width': '120px'
                        });
                    }
                }, { shadeClose: true });
                $.ajax({
                    url: '../ProCheck/createReport',
                    data: { pchCodes: pchCodes },
                    dataType: "json",
                    type: "POST",
                    success: function (data) {
                        if (data.result) {
                            layer.msg("报告生成成功");
                            var conditon = JSON.stringify(FormToJson("qForm"));
                            reLoadTable("list", "../ProCheck/GetDataList?dataType=task&condition=" + conditon,currPage);
                        } else {
                            layer.msg(data.message);
                        }
                        layer.close(loadwin);
                        canCreatebg = true;
                    }
                });
            } 
            else {
            layer.msg("请先选择盘点任务"); return;
            }
    }

</script>